package com.yihu.wlyy.web.patient.family;

import com.yihu.wlyy.entity.WlyyPatientInviteLog;
import com.yihu.wlyy.service.app.family.FamilyService;
import com.yihu.wlyy.web.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by Administrator on 2016.08.20.
 */
@Controller
@RequestMapping("/patient/family")
public class PatientFamilyController extends BaseController {
    @Autowired
    private FamilyService familyService;


    /**
     * 查询医生是否有邀请改患者
     *
     * @param doctorCode 医生code
     * @return
     */
    @ResponseBody
    @RequestMapping("/getPatientInviteLog")
    public String getPatientInviteLog(String doctorCode, String invitePatientCode) {
        try {
            WlyyPatientInviteLog wlyyPatientInviteLog = familyService.getPatientInviteLog(doctorCode, getUID(), invitePatientCode);
            if (wlyyPatientInviteLog != null) {
                return write(200, "查询成功!", "data", wlyyPatientInviteLog);
            }
            return write(200, "查询成功!", "data", "");
        } catch (Exception e) {
            error(e);
            return error(-1, "更新已读失败！");
        }
    }

    @ResponseBody
    @RequestMapping("/findPatientInviteLog")
    public String findPatientInviteLog(String invitePatientCode) {
        try {
            WlyyPatientInviteLog wlyyPatientInviteLog = familyService.getPatientInviteLog( invitePatientCode);
            if (wlyyPatientInviteLog != null) {
                return write(200, "查询成功!", "data", wlyyPatientInviteLog);
            }
            return write(200, "查询成功!", "data", "");
        } catch (Exception e) {
            error(e);
            return error(-1, "更新已读失败！");
        }
    }

    /**
     * 更新邀请日志
     * @param patientInviteLogCode
     * @param type
     * @return
     */
    @ResponseBody
    @RequestMapping("/updatePatientInviteLog")
    public String updatePatientInviteLog(String patientInviteLogCode,
                                         String type) {
        try {
           familyService.updatePatientInviteLog(patientInviteLogCode, getUID(), type);

            return write(200, "更新成功!");
        } catch (Exception e) {
            error(e);
            return error(-1, "更新失败！"+e.getMessage());
        }
    }
}
